<template>
  <!--微信组件-->
  <van-pull-refresh v-model="refreshLoading" @refresh="onRefresh">
  <div id="wechat">
      <ul class="wechat-list" v-if="MsgListNumber>0">
        <!--props传递消息对象 baseMsgObj -->
        <!-- <msg-item v-for="baseMsgObj in $store.state.msgList.baseMsg" :item="baseMsgObj" class="list-row line-bottom" :key="baseMsgObj.mid"></msg-item> -->
        <msg-item2
          v-for="baseMsgObj in baseMsgList"
          :item="baseMsgObj"
          class="list-row line-bottom"
          :key="baseMsgObj.mid"
        />
      </ul>
      <div class="notMessage" v-else>暂无会话</div>
  </div>
   </van-pull-refresh>
</template>
<script>
import msgItem from "../wechat/msg-item";
import msgItem2 from "../wechat/msg-item2";
import { ApiGetDialogueList } from "@/api/api/main";
import { PullRefresh } from "vant";

export default {
  components: {
    msgItem,
    msgItem2,
    [PullRefresh.name]: PullRefresh,
  },
  mixins: [window.mixin],
  data() {
    return {
      pageName: "会话列表",
      loading: false,
      refreshLoading: false,
    };
  },
  mounted: function () {
    if (this.$store.state.newMsgCount > 0) {
      this.pageName += "(" + this.$store.state.newMsgCount + ")";
    }
    this.init();
  },
  activated() {
    if (this.$route?.query?.init == 1) {
      this.init();
    }
  },
  //方法集列表
  methods: {
    init() {
      if (this.loading) return;
      this.loading = true;
      // 在这里 会话列表的拉取
      ApiGetDialogueList({ reject: 1 })
        .then((res) => {
          let data = res.data;
          this.loading = false;
          this.refreshLoading = false;
          this.$store.commit("setMsgList", data);
        })
        .catch(() => {
          this.loading = false;
          this.refreshLoading = false;
        });
    },
    onRefresh() {
      console.log("列表刷新");
      this.init();
    },
  },
  computed: {
    baseMsgList() {
      return this.$store.state.msgList.baseMsg;
    },
    MsgListNumber(){
      let number = 0
      for(let i in this.baseMsgList){
        if(this.baseMsgList[i].is_show==1){
          number+=1
        }
      }
      return number
    }
  },
  watch: {
    baseMsgList(val) {
      // console.log(val,'--valusssss')
    },
  },
};
</script>
<style lang="less">
@import "../../assets/less/wechat.less";

#wechat .wechat-list .list-row .backgray {
  background-color: #eee;
}

.notMessage{
  text-align: center;
  font-size: 16px;
  color: #999;
  margin-top: 20px;
}
// .app-content,#wechat,.van-pull-refresh{
//     height: 100%;
//     overflow-y: hidden;
// }
</style>